﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CarbonExchange.Bll
{
    public class AmeeItem
    {
        public string Id { get; internal set; }
        public DateTime Created { get; internal set; }
        public string Path { get; internal set; }
        internal List<AmeeProfileItemProperty> ItemValues { get; set; }
        public string Name { get; set; }

        public T GetValue<T>(string path)
        {
            if (ItemValues == null)
            {
                return default(T);
            }

            var tmp = ItemValues.Where(x => x.Path == path).FirstOrDefault();
            if (tmp != null)
            {
                return tmp.GetValue<T>();
            }
            else
            {
                return default(T);
            }
        }

        public void SetValue<T>(string path, T value)
        {
            if (ItemValues == null)
            {
                ItemValues = new List<AmeeProfileItemProperty>();
            }
            var tmp = ItemValues.Where(x => x.Path == path).FirstOrDefault();
            if (tmp == null)
            {
                ItemValues.Add(new AmeeProfileItemProperty(path, value));
            }
            else
            {
                tmp.SetValue(value);
            }
        }
    }
}
